// pages/my/mycoins/mycoins.js
Page({
  data: {
    isSign: false,
    sign_show: false,
    task_show: false,
    integral: {},
    taskList: [{
      name: "每日签到",
      reward: "1",
      action: "sign"
    }, {
      name: "发布一条心情动态",
      reward: "2",
      action: "/pages/add/mood/mood"
    }, {
      name: "给1个邻居动态点个赞",
      reward: "1",
      action: "/pages/dynamic/dynamic"
    }, {
      name: "给10个邻居动态点个赞",
      reward: "3",
      action: "/pages/dynamic/dynamic"
    }, {
      name: "发布一条自家售卖商品",
      reward: "1",
      action: "/pages/add/sell/sell"
    }, {
      name: "发布一条出租招租信息",
      reward: "1",
      action: "/pages/add/rent/rent"
    }, {
      name: "发布一条二手商品信息",
      reward: "1",
      action: "/pages/add/oldgood/oldgood"
    }, {
      name: "发布一条旅游代买信息",
      reward: "1",
      action: "/pages/add/travelbuy/travelbuy"
    }, {
      name: "发布个人技能服务",
      reward: "1",
      action: "/pages/add/skills/skills"
    }, {
      name: "给小程序提建议",
      reward: "1",
      action: "/pages/my/feedback/feedback"
    }],
    weekStatus: [],
    taskStatus: []
  },
  onLoad: function (options) {},
  onShow: function () {
    this.myIntegral();
    this.getStatus();
    this.todayTask();
  },
  sign() {
    getApp().globalData.http.sign().then(res => {
      this.setData({
        sign_show: true
      });
      this.myIntegral();
      this.getStatus();
      this.todayTask();
    }).catch(e => {
      getApp().globalData.vant.toast.fail(e.msg);
    });
  },
  toDoTask() {
    this.setData({
      task_show: true
    });
  },
  exchange() {
    wx.navigateTo({
      url: "/pages/my/mycoinsfor/mycoinsfor",
    })
  },
  exchangerecord() {
    wx.navigateTo({
      url: "/pages/my/exchangerecord/exchangerecord",
    })
  },
  myIntegral() {
    getApp().globalData.http.myIntegral().then(res => {
      this.setData({
        integral: res.data
      });
    });
  },
  getStatus() {
    getApp().globalData.http.weekSign().then(res => {
      let tmp = res.data;
      tmp.forEach(item => {
        item.day = item.date.split("-")[2];
        if (item.date.split("-")[2] == new Date().getDate() && item.status == 1) {
          this.setData({
            isSign: true
          });
        }
        switch (item.week) {
          case 1:
            item.weekStr = "周一";
            break;
          case 2:
            item.weekStr = "周二";
            break;
          case 3:
            item.weekStr = "周三";
            break;
          case 4:
            item.weekStr = "周四";
            break;
          case 5:
            item.weekStr = "周五";
            break;
          case 6:
            item.weekStr = "周六";
            break;
          case 0:
            item.weekStr = "周日";
        }
      });
      this.setData({
        weekStatus: tmp
      });
    });
  },
  todayTask() {
    getApp().globalData.http.todayTask().then(res => {
      this.setData({
        taskStatus: res.data
      });
    });
  },
  todo(e) {
    let action = e.currentTarget.dataset.action;
    if (action == "sign") {
      this.sign();
    } else {
      wx.navigateTo({
        url: action,
      })
    }
  }
})